package com.xiaoxu.hdfsProject;

/**
 * 自定义wc实现类顾客
 */
public class WordCountMapper implements MyMapper {

    public void map(String line, MyContext context) {
        //line = "hadoop	welcome"
        String[] words = line.split("\t");
        //words = [hadoop,welcome]

        for(String word : words) {
            //word1 = hadoop  word2 = welcome
            Object value = context.get(word);
            if(value == null) { // 表示没有出现过该单词
                context.write(word, 1);
            } else {
                int v = Integer.parseInt(value.toString());
                context.write(word, v+1);  // 取出单词对应的次数+1
            }
        }

    }
}
